package com.wyy.controller;

import com.wyy.beans.Driver;
import com.wyy.service.DriverService;
import com.wyy.common.Result;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api")
public class DriverController {

    @Autowired
    private DriverService driverService;

    @PostMapping("/driver")
    @RequiresRoles("admin")
    public Result<Driver> addDriver(@RequestBody Driver driver) {
        return driverService.addDriver(driver);
    }

    @DeleteMapping("/driver/{id}")
    @RequiresRoles("admin")
    public Result<Driver> deleteDriver(@PathVariable long id) {
        return driverService.deleteDriver(id);
    }

    @PutMapping("/driver")
    @RequiresRoles("admin")
    public Result<Driver> updateDriver(@RequestBody Driver driver) {
        return driverService.updateDriver(driver);
    }

    @GetMapping("/driver/{id}")
    public Result<Driver> getDriver(@PathVariable long id) {
        return driverService.getDriver(id);
    }

    @GetMapping("/drivers")
    public Result<List<Driver>> getDrivers() {
        return driverService.getDrivers();
    }

}
